//
//  TimeUtils.m
//  JiaoX
//
//  Created by yinqy on 15/1/12.
//  Copyright (c) 2015年 北京娇羞科技有限公司. All rights reserved.
//

#import "TimeUtils.h"

@implementation TimeUtils

/**
 * 计算剩余抢购时间
 *
 * @param timeMillis 最后结束日期
 *
 * @return 剩余时间, 单位是秒
 */
+(long long)getRemainTime:(long long)timeMillis{
    long long currentTimeMillis = [[NSDate date] timeIntervalSince1970]*1000;
    return timeMillis - currentTimeMillis;
}

/**
 * 得到格式化后的剩余时间
 *
 * @param timeMillis 剩余时间，long类型精确到毫秒,
 * @return 时：分 的字符串格式
 */
+ (NSString *)getFormatRemainTime:(long long)timeMillis{
    long long cutLong = timeMillis / 1000;
    NSMutableString *strin = [NSMutableString string];
    int hour = (int) cutLong / (60 * 60);
    int min = (int) (cutLong - hour * 60 * 60) / 60;
    [strin appendString:hour > 0 ? [NSString stringWithFormat:@"%d小时",hour]:@""];
    [strin appendString:min > 0 ? [NSString stringWithFormat:@"%d分",min]:@"1分"];
    return strin;
}

/**
 * 获取当前格式化时间
 *
 * @return
 */
+ (NSString *)getFormatCurrentTime{
    NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
    [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSString *dateTime = [formatter stringFromDate:[NSDate date]];
    return dateTime;
}

@end
